package com.daykw.wkinfo.utils;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Const {

	// @Autowired
	// private Environment environment;

	@Value("${article_thread}")
	private Boolean article_thread;
	@Value("${search_topic}")
	private Boolean search_topic;
	@Value("${search_biz}")
	private Boolean search_biz;
	@Value("${list_thread}")
	private Boolean list_thread;
	@Value("${search_date}")
	private Boolean search_date;
	

	public static int FIAL_400 = 400;
	public static int FIAL_500 = 500;
	public static int FIAL = 999;
	public static int SUC = 200;

	public static String getLocalHostIp() throws Exception {
		try {
			String ip = null;
			InetAddress candidateAddress = null;
			// 遍历所有的网络接口
			for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); ifaces
					.hasMoreElements();) {
				NetworkInterface iface = ifaces.nextElement();
				// 在所有的接口下再遍历IP
				for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
					InetAddress inetAddr = inetAddrs.nextElement();
					if (!inetAddr.isLoopbackAddress()) {// 排除loopback类型地址
						if (inetAddr.isSiteLocalAddress()) {
							// 如果是site-local地址，就是它了
							candidateAddress = inetAddr;
						} else if (candidateAddress == null) {
							// site-local类型的地址未被发现，先记录候选地址
							candidateAddress = inetAddr;
						}
					}
				}
			}
			// 如果没有发现 non-loopback地址.只能用最次选的方案
			if (candidateAddress == null) {
				candidateAddress = InetAddress.getLocalHost();
			}
			ip = candidateAddress.getHostAddress();

			return ip;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	

	public Boolean getArticle_thread() {
		return article_thread;
	}



	public void setArticle_thread(Boolean article_thread) {
		this.article_thread = article_thread;
	}



	public Boolean getSearch_topic() {
		return search_topic;
	}

	public void setSearch_topic(Boolean search_topic) {
		this.search_topic = search_topic;
	}

	public Boolean getSearch_biz() {
		return search_biz;
	}

	public void setSearch_biz(Boolean search_biz) {
		this.search_biz = search_biz;
	}

	public Boolean getList_thread() {
		return list_thread;
	}

	public void setList_thread(Boolean list_thread) {
		this.list_thread = list_thread;
	}

	public Boolean getSearch_date() {
		return search_date;
	}

	public void setSearch_date(Boolean search_date) {
		this.search_date = search_date;
	}

}
